#include <iostream>
#include <string.h>
using namespace std;
// [x]解决输出问题
struct student
{
    char num[20];
    char f[20];
    char s[20];
    char t[20];
};

int check(student *a, student *b);

int main()
{
    int num = 0;
    int t;
    cin >> t;
    student *stu = new student[t];
    for (int i = 0; i < t; i++)
    {
        cin >> stu[i].num >> stu[i].f >> stu[i].s >> stu[i].t;
    }

    for (int i = 0; i < t - 1; i++)
    {
        for (int j = i + 1; j < t; j++)
        {
            num = check(stu + i, stu + j);
            // cout << num << endl;
            if (num != 0)
            {
                cout << stu[i].num << " " << stu[j].num << " " << num << endl;
            }
        }
    }
    return 0;
}

int check(student *a, student *b)
{
    int t1, t2, t, cnt = 0;

    char *p1, *p2;
    p1 = a->f;
    p2 = b->f;
    t1 = strlen(p1);
    t2 = strlen(p2);
    for (int i = 1; i <= 3; i++)
    {
        cnt = 0;
        t = t1;
        if (t2 < t)
        {
            t = t2;
        }
        // cout << t << endl;
        for (int j = 0; j < t; j++)
        {

            if (*(p1 + j) == *(p2 + j))
            {
                cnt++;
            }

            if (cnt >= 0.9 * t)
            {
                return i;
            }
        }
        if (i == 1)
        {
            p1 = a->s;
            p2 = b->s;
            t1 = strlen(p1);
            t2 = strlen(p2);
        }
        if (i == 2)
        {
            p1 = a->t;
            p2 = b->t;
            t1 = strlen(p1);
            t2 = strlen(p2);
        }
    }
    return 0;
}
